<?php
defined('SYSPATH') or die('No direct script access.');

class Model_FeedBack extends Model_Base{

	protected $_table_name  = 'feedBack';
	protected $_table_names_plural = false;

	public function insert($desc,$type,$contact){
		if (!$this->is_Utf8($desc)){
			$desc = mb_convert_encoding($desc, "utf-8", "gb2312");
		}
		$this->desc = $desc;
		$this->type = $type;
		if (!empty($contact)){
			$this->contact = $contact;
		}
		$this->createtime = Date::formatted_time();
		
		return $this->save();
	}

	protected function modelWithCondition($filters){
		$model = $this->where("status","=","A");
		return $model;
	}
	
	public function displayProcess(){
		if($this->process == "N" ||$this->process == "n" ){
			return "未处理";
		}elseif ($this->process == "Y" ||$this->process == "y" ){
			return "已处理";
		}
		return "";
	}
	
	public function diplaySupplier(){
		$arr = split(":::::SupplierId-", $this->desc);
		if (sizeof($arr) > 1 && intval($arr[1]) > 0){
			return ORM::factory("supplier",$arr[1])->name."&nbsp;&nbsp;";
		}
		return "";
	}
	
	public function displayType(){
		if($this->type == "E" ||$this->type == "e" ){
			return "信息报错";
		}elseif ($this->type == "F" ||$this->type == "f" ){
			return "意见反馈";
		}
		return "";
	}
	
	public function isProcessd(){
		if($this->process == "N" ||$this->process == "n" ){
			return false;
		}elseif ($this->process == "Y" ||$this->process == "y" ){
			return true;
		}
		return false;
	}
}